import { invoke } from '@tauri-apps/api/core'
import { listen } from '@tauri-apps/api/event';
export async function install(path: string): Promise<void> {
  return await invoke<{value?: string}>('plugin:install|install', {
    payload: {
      path,
    },
  }).then();
}

export async function download(url: string, path: string, callback: (arg0: { progressTotal: number; total: number; }) => void) {
  listen<{progressTotal: number, total: number}>('/file/download', async (event) => {
    const {progressTotal, total} = event.payload;
    callback({progressTotal: progressTotal, total: total});
  });
  return await invoke<{url: string, path: string}>('plugin:install|download', {
    payload: {
      url, path
    }
  });
}